home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / OpenTransport / Interfaces / CIncludes / ddrt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-17  |  5.1 KB  |  184 lines  |  [TEXT/MPS ]

  1. /************************************************************
  2.  
  3.     ddrt.h
  4.  
  5.     Types and functions used for emulating PowerPC "double double"
  6.     arithmetic. The "double double" type is the implementation
  7.     of the "long double" 'C' data type as supported on Apple's
  8.     PowerPC computers by Apple's PowerPC compilers.
  9.     
  10.     Certain function names were previously defined by IBM™
  11.     for their AIX runtime environment.  They are provided here
  12.     for backward compability.
  13.  
  14.     Copyright Apple Computer,Inc.  1996
  15.     All rights reserved
  16.  
  17. ************************************************************/
  18.  
  19. #ifndef __DDRT_H__
  20. #define __DDRT_H__
  21.  
  22. #include <ConditionalMacros.h>
  23. #include <fp.h>
  24. #include <fenv.h>
  25.  
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29.  
  30. #if        GENERATINGPOWERPC
  31.  
  32. typedef long double DD;                            /*    Use native "long double".        */
  33. typedef decimal decimalDD;
  34.  
  35. #define __fpsetdblprec() ((void)0)
  36. #define __fpsetextprec() ((void)0)
  37.  
  38. #else    /* not GENERATINGPOWERPC */
  39.  
  40. #define __fpsetdblprec() fesetprec(FE_DBLPREC)
  41. #define __fpsetextprec() fesetprec(FE_LDBLPREC)
  42.  
  43. #define            SIGDIGLENDD        36                /*    significant decimal digits        */
  44. #define            MAXDIGITS        SIGDIGLENDD
  45.  
  46. struct decimalDD 
  47. {
  48.     char sgn;                                    /*    sign 0 for +, 1 for -            */
  49.     char unused;
  50.     short exp;                                    /*    decimal exponent                */
  51.     struct
  52.     {
  53.         unsigned char length;
  54.         unsigned char text[SIGDIGLENDD];        /*    significant digits                */
  55.         unsigned char unused;
  56.     } sig;
  57. };
  58.  
  59. typedef struct decimalDD decimalDD;
  60.  
  61. typedef struct                                    /*    "long double" on the PowerPC    */
  62. {                                                /*    is just a pair of doubles.        */
  63.     double hi;
  64.     double lo;
  65. } DD;
  66.  
  67. /*    These routines are similar to the corresponding routines in <fp.h>
  68.  *    except that these routines run on the 68000 family.
  69.  */
  70.  
  71.  
  72. extern void num2decl ( const decform *f, DD x, decimalDD *d );
  73.  
  74. extern void num2decDD ( const decform *f, double x, decimalDD *d );
  75.  
  76. extern DD dec2numDD ( const decimalDD *d );
  77.  
  78. extern void str2decDD ( const char *s, short *ix, decimalDD *d, short *vp ); 
  79.  
  80. extern DD str2numDD (const char *s);
  81.  
  82. #endif    /* GENERATINGPOWERPC */
  83.  
  84. /*    Basic operations    */
  85. extern DD _xlqadd( DD x, DD y );
  86. extern DD _xlqsub( DD x, DD y );
  87. extern DD _xlqmul( DD x, DD y );
  88. extern DD _xlqdiv( DD x, DD y );
  89. extern DD __negdd( DD x );
  90.  
  91.  
  92. /*    Type conversions    */
  93. extern DD __int2dd( int n );
  94. extern DD __uns2dd( unsigned ui );
  95. extern DD __flt2dd( float f );
  96. extern DD __dbl2dd( double d );
  97. extern int __dd2int( DD x );
  98. extern unsigned int __dd2uns( DD x );
  99. extern float __dd2flt( DD x );
  100. extern double __dd2dbl( DD x );
  101.  
  102. extern DD _qint(DD x);  /*    truncates x to DD integer.    */
  103.  
  104. #define _HEAD(x) ((double *)&x)[0]
  105. #define _TAIL(x) ((double *)&x)[1]
  106.  
  107. /* Macro forms of the relational operator routines. */
  108.  
  109. #define _EQ(x,y) (_HEAD(x) == _HEAD(y) && _TAIL(x) == _TAIL(y))
  110. #define _NE(x,y) (_HEAD(x) != _HEAD(y) || _TAIL(x) != _TAIL(y))
  111. #define _GT(x,y) (_HEAD(x) > _HEAD(y) || (_HEAD(x) == _HEAD(y) && _TAIL(x) > _TAIL(y)))
  112. #define _LT(x,y) (_HEAD(x) < _HEAD(y) || (_HEAD(x) == _HEAD(y) && _TAIL(x) < _TAIL(y)))
  113. #define _LE(x,y) (_LT(x,y) || _EQ(x,y))
  114. #define _GE(x,y) (_GT(x,y) || _EQ(x,y))
  115. #define _UNORDERED(x,y) \
  116. ( \
  117.     _HEAD(x) != _HEAD(x) || _HEAD(y) != _HEAD(y) || \
  118.     _TAIL(x) != _TAIL(x) || _TAIL(y) != _TAIL(y)    \
  119. )
  120.  
  121. /* Relational operators */
  122. extern int __ddeq(DD x, DD y);        /* x == y */
  123. extern int __ddne(DD x, DD y);        /* x != y */
  124. extern int __ddgt(DD x, DD y);        /* x >  y */
  125. extern int __ddge(DD x, DD y);        /* x >= y */
  126. extern int __ddlt(DD x, DD y);        /* x <  y */
  127. extern int __ddle(DD x, DD y);        /* x <= y */
  128. extern int __ddunordered(DD x, DD y); /* x unordered y */
  129.  
  130.  
  131. /* Emulation routine for the PowerPC's Multiply-Add-Fused instruction:
  132.  *    (x*y + z)
  133.  */
  134. extern double MAF( double x, double y, double z );
  135.  
  136. /* The possible values returned by "_qatof".    */
  137. typedef enum
  138. {
  139.     NoConversionError = 0,
  140.     PositiveOverFlow = 1,
  141.     NegativeOverFlow = 2,
  142.     Underflow = 3,
  143.     DenormalizedNumber = 4
  144. } ConversionErrorFlagType;
  145.  
  146. /*
  147.  * Similar to "atof"
  148.  * "_qatof" converts the charater string "s" into a "DD"
  149.  * "ld" points to the result.
  150.  * The return value gives a possible conversion error.
  151.  */
  152.  
  153. extern int _qatof(DD *ld, const char *s);
  154.  
  155. /*
  156.  * Similar to "ecvt" and "fcvt".
  157.  * Converts "value" to a decimal string.
  158.  * "ndigit" is the number of digits to use in the string.
  159.  * "decpt" will be the character position of the decimal point.
  160.  * "sign" will be 0 for positive, 1 for negative.
  161.  * "_qecvt" uses the "e" format, producing a floating point number with exponent.
  162.  * "_qecvt" uses the "f" format, producing a fixed point number.
  163.  * "__g_fmt" uses the "g" format, using either fixed or floating point depending on the value.
  164.  *   The buffer "output" should be at least 64-bytes long.
  165.  *
  166.  * Note:
  167.  *  Due to the nature of the "DD" type, it is not always possible to print
  168.  * a decimal string that can acurately represent the binary value.  Under
  169.  * these conditions, the binary->decimal->binary round trip conversion
  170.  * cannot be guaranteed with less than 600 decimal digits.
  171.  */
  172.  
  173. extern char *_qecvt (DD value, int ndigit, int *decpt, int *sign);
  174. extern char *_qfcvt (DD value, int ndigit, int *decpt, int *sign);
  175. extern void __g_fmt (char *output, DD value);
  176.  
  177.  
  178. #ifdef __cplusplus
  179. }            /* extern "C" */
  180. #endif
  181.  
  182. #endif    /* __DDRT_H__ */
  183.  
  184.